<?php
namespace app\admin\controller;

use think\Session;
use think\Validate;
use app\common\model\Imgclass as A;
use app\common\model\Imglogo as B;
class Imgclass  extends Common
{
    //logo提交
    public function in_logo()
    {
        //获取管理员
       $logodata=db('logo')->find();
        $this->assign('logodata',$logodata);
		//导航管理
        $daoh=$this->auth_group();
        $ssname=Session::get('admin_username');
        $this->assign('ssname',$ssname);
        $this->assign('daoh',$daoh);
		if(request()->isPost())
            {
				//halt($_POST);
               $logo_add=new B();
                $res=$logo_add->logo_add(input('post.'));
                    $mess=array(
                        'status'=>$res['valid'],
                        'message'=>$res['msg']
                    );
                    return $mess;
            }
		
		
        return $this->fetch();
    }
    //轮播图
    public function in_carousel()
    {
		//获得轮播图信息
		$carodata=db('carousel')->where('caro_states',1)->select();
        $this->assign('carodata',$carodata);
        //导航管理
        $daoh=$this->auth_group();
        $ssname=Session::get('admin_username');
        $this->assign('ssname',$ssname);
        $this->assign('daoh',$daoh);
		return $this->fetch();
    }
	
	//上传图片
	public function upload(){
    // 获取表单上传文件 例如上传了001.jpg
    	$path ="/uploads/";
        $file = request()->file('file');
        // 移动到框架应用根目录/public/uploads/ 目录下
        $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
        if($info){
    	// 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
    	$path = $path . $info->getSaveName();
    	
            // 成功上传后 返回上传信息
    	return json(array('state'=>1,'path'=>$path));
        }else{
            // 上传失败返回错误信息
    	return json(array('state'=>0,'errmsg'=>'上传失败'));
        }
	}
	//添加轮播图
	public function caro_add()
	{
	   //halt($admin);
       if(request()->isPost())
            {
				//halt($_POST);
               $caro_add=new A();
                $res=$caro_add->caro_add(input('post.'));
                    $mess=array(
                        'status'=>$res['valid'],
                        'message'=>$res['msg']
                    );
                    return $mess;
            }
		
		
         //return $this->fetch();
     
	}
	//删除轮播图(假删)
	public function caro_dele()
	{
		if(request()->isPost())
            {
				//halt($_POST);
               $caro_dele=new A();
                $res=$caro_dele->caro_dele(input('post.'));
                    $mess=array(
                        'status'=>$res['valid'],
                        'message'=>$res['msg']
                    );
                    return $mess;
            }

         
	}
    //删除轮播图
    public function caro_deled()
    {
        if(request()->isPost())
            {
                //halt($_POST);
               $caro_dele=new A();
                $res=$caro_dele->caro_deled(input('post.'));
                    $mess=array(
                        'status'=>$res['valid'],
                        'message'=>$res['msg']
                    );
                    return $mess;
            }

         
    }
    //上架
    public function caro_update()
    {
        if(request()->isPost())
            {
                //halt($_POST);
               $caro_dele=new A();
                $res=$caro_dele->caro_update(input('post.'));
                    $mess=array(
                        'status'=>$res['valid'],
                        'message'=>$res['msg']
                    );
                    return $mess;
            }

         
    }
	//修改轮播图
	public function  edit_carousel()
	{
		$carodata=db('carousel')->where('caro_states',1)->select();
        $this->assign('carodata',$carodata);
        //导航管理
        $daoh=$this->auth_group();
        $ssname=Session::get('admin_username');
        $this->assign('ssname',$ssname);
        $this->assign('daoh',$daoh);
		//修改信息

		$caro=input('param.');
		//获得信息
		$data=db('carousel')->where('caro_id',$caro['caro_id'])->find();
		$this->assign('data',$data);
		
		
		//更新
		 if(request()->isPost())
            {
				//halt($_POST);
               $caro_edit=new A();
                $res=$caro_edit->caro_edit(input('post.'));
                    $mess=array(
                        'status'=>$res['valid'],
                        'message'=>$res['msg']
                    );
                    return $mess;
            }
		
        return $this->fetch();
	}
	
	
}
	

